package com.zsc.wxm.ysh.anjo.house.controller;

import com.zsc.wxm.ysh.anjo.house.service.ViewRequestService;
import com.zsc.wxm.ysh.anjo.result.PageResult;
import com.zsc.wxm.ysh.anjo.result.Result;
import com.zsc.wxm.ysh.anjo.service.base.model.member.dto.ViewRequestDTO;
import com.zsc.wxm.ysh.anjo.service.base.model.resources.qo.ViewRequestQuery;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 描述：看房请求
 *
 * @author playmaker
 * @since 2021/2/19 22:56
 */
@RestController
@RequestMapping("/house/view-request")
public class ViewRequestController {

    @Resource
    private ViewRequestService service;

    @PostMapping("/add")
    @ApiOperation("增加看房请求")
    public Result add(@Validated @RequestBody ViewRequestDTO params) {
        service.add(params);
        return Result.ok("已发送看房请求");
    }

    @PostMapping("/list-page")
    @ApiOperation("分页查询")
    public PageResult listPage(@RequestBody ViewRequestQuery params) {

        return service.listPage(params);
    }

    @PutMapping("/update-status/{id}/{status}/{userId}")
    @ApiOperation("更新请求状态")
    public Result updateStatus(@PathVariable("id") Long id, @PathVariable("status") int status, @PathVariable("userId") Long userId) {
        service.updateStatus(id, status, userId);
        return Result.ok("更改成功");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public Result delete(@PathVariable("id") Long id) {
        return service.deleteRequest(id);
    }

    @GetMapping("/view-request-details/{id}")
    @ApiOperation("获取请求详情")
    public Result viewRequestDetails(@PathVariable("id") Long id) {
        Map<String, Object> data = new HashMap<>();
        data.put("viewRequest", service.viewRequestDetails(id));
        return Result.ok("获取成功", data);
    }

    @GetMapping("/get-request-notice/{userId}")
    @ApiOperation("获取看房通知")
    public Result getRequestNotice(@PathVariable("userId") Long userId) {
        Map<String, Object> data = new HashMap<>(1);
        data.put("list", service.getRequestNotice(userId));
        return Result.ok("获取成功", data);
    }

    @GetMapping("/get-rent-request-notice/{rentUserId}")
    @ApiOperation("获取租客通知")
    public Result getRentUserNotice(@PathVariable("rentUserId") Long rentUserId) {
        Map<String, Object> data = new HashMap<>(1);
        data.put("list", service.getRentUserNotice(rentUserId));
        return Result.ok("获取成功", data);
    }
}
